/**
 * Source file: OnBlur_Retrenchment_Claim_Form.ejs
 * Copyright (C) 2013 : Quantum Solutions
 * Id: $Id: OnBlur_RetrenchmentClaim.ejs 123 2013-04-29 20:29:19Z WillieVisagie55@gmail.com $
 * Date: $Date: 2013-04-29 22:29:19 +0200 (Mon, 29 Apr 2013) $
 */
 
var prevField = ""; 
function Field_onBlur(f) {
	prevField = f;
}

function Field_onFocus(f){
	//alert ("Field_onFocus:" + f.name );
	
	// only validate when we change fields
	// (ie can blur a field without leaving it! amazing! no!)
	if (f.name != prevField.name) {
		validateFields(prevField);
	}
}	

function validateFields(f) {
	 //alert("validateFields: "+f.name);
//Postal Code Validation
	if(f.name=="Code") {
		CheckPostal("Suburb","Code");
//IDNumber Validation
	} else if(f.name=="IDNumber") {
		if (!IDNoValidater(EFormGetValue("IDNumber")) && EFormGetValue("IDNumber") != ""){
			alert("Main member IDnumber is invalid: " + EFormGetValue("IDNumber"));				
			EFormSetFocus(EFormGetField("IDNumber"));  
		}
//Date Validations
	} else if (f.name=="Datepolicycommenced") {
		if (!CheckDate(EFormGetValue("Datepolicycommenced")) && EFormGetValue("Datepolicycommenced") != ""){
			//alert("Invalid date: " + EFormGetValue("Datepolicycommenced"));
			EFormSetFocus(EFormGetField("Datepolicycommenced")); 
		}
	} else if (f.name=="DOE") {
		if (!CheckDate(EFormGetValue("DOE")) && EFormGetValue("DOE") != ""){
			//alert("Invalid date: " + EFormGetValue("DOE"));
			EFormSetFocus(EFormGetField("DOE")); 
		}
	} else if (f.name=="DOA") {
		if (!CheckDate(EFormGetValue("DOA")) && EFormGetValue("DOA") != ""){
			//alert("Invalid date: " + EFormGetValue("DOA"));
			EFormSetFocus(EFormGetField("DOA")); 
		}
	} else if (f.name=="DOS") {
		if (!CheckDateNoFutureCheck(EFormGetValue("DOS")) && EFormGetValue("DOS") != ""){
			//alert("Invalid date: " + EFormGetValue("DOS"));
			EFormSetFocus(EFormGetField("DOS")); 
		}
	} else if (f.name=="DOR") {
		if (!CheckDateNoFutureCheck(EFormGetValue("DOR")) && EFormGetValue("DOR") != ""){
			//alert("Invalid date: " + EFormGetValue("DOR"));
			EFormSetFocus(EFormGetField("DOR")); 
		}
	} else if (f.name=="Date_of_event") {
		if (!CheckDate(EFormGetValue("Date_of_event")) && EFormGetValue("Date_of_event") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_of_event"));
			EFormSetFocus(EFormGetField("Date_of_event")); 
		}
	} else if (f.name=="DOJE") {
		if (!CheckDate(EFormGetValue("DOJE")) && EFormGetValue("DOJE") != ""){
			//alert("Invalid date: " + EFormGetValue("DOJE"));
			EFormSetFocus(EFormGetField("DOJE")); 
		}
	} else if (f.name=="DOLWD") {
		if (!CheckDate(EFormGetValue("DOLWD")) && EFormGetValue("DOLWD") != ""){
			//alert("Invalid date: " + EFormGetValue("DOLWD"));
			EFormSetFocus(EFormGetField("DOLWD")); 
		}
	} else if (f.name=="AcceptOfferComDate") {
		if (!CheckDateNoFutureCheck(EFormGetValue("AcceptOfferComDate")) && EFormGetValue("AcceptOfferComDate") != ""){
			//alert("Invalid date: " + EFormGetValue("AcceptOfferComDate"));
			EFormSetFocus(EFormGetField("AcceptOfferComDate")); 
		}
	} else if(f.name=="ADTelWork") {
		if (!TelNoValidater(EFormGetValue("ADTelWork")) && EFormGetValue("ADTelWork") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("ADTelWork"));				
			EFormSetFocus(EFormGetField("ADTelWork"));  
		} 
	} else if(f.name=="AcceptedOfferContactno") {
		if (!TelNoValidater(EFormGetValue("AcceptedOfferContactno")) && EFormGetValue("AcceptedOfferContactno") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("AcceptedOfferContactno"));				
			EFormSetFocus(EFormGetField("AcceptedOfferContactno"));  
		} 
	} else if(f.name=="Home_Number") {
		if (!TelNoValidater(EFormGetValue("Home_Number")) && EFormGetValue("Home_Number") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Home_Number"));				
			EFormSetFocus(EFormGetField("Home_Number"));  
		} 
	} else if(f.name=="Work_Number") {
		if (!TelNoValidater(EFormGetValue("Work_Number")) && EFormGetValue("Work_Number") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Work_Number"));				
			EFormSetFocus(EFormGetField("Work_Number"));  
		} 
	} else if(f.name=="Cell_Number") {
		if (!TelNoValidater(EFormGetValue("Cell_Number")) && EFormGetValue("Cell_Number") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Cell_Number"));				
			EFormSetFocus(EFormGetField("Cell_Number"));  
		} 
	}
	
    return true;
}